<!DOCTYPE html>
<html>
<head>
    <title>Hover popUp Demo</title>
</head>
<body>
<div>
	<!-- 图片 -->
	<img id="1" src="https://t7.baidu.com/it/u=1595072465,3644073269&fm=193&f=GIF" style="width: 310.4px; height: 310px; background-color: rgb(79, 102, 51); alt="描述性文本" class="hover-box">
	
	<img id="2" src="https://t7.baidu.com/it/u=1595072465,3644073269&fm=193&f=GIF" style="width: 310.4px; height: 310px; background-color: rgb(79, 102, 51); alt="描述性文本" class="hover-box">

	<img id="3" src="https://t7.baidu.com/it/u=1595072465,3644073269&fm=193&f=GIF" style="width: 310.4px; height: 310px; background-color: rgb(79, 102, 51); alt="描述性文本" class="hover-box">
</div>
<div class="popUp">
	<button type="button" class="search-btn" onclick="getElementObj()">搜索</button>
</div>
<style>
	body {
	  display: flex;
	  justify-content: center;
	  align-items: center;
	  height: 100vh;
	  margin: 0;
	}
	
    .popUp {
        position: absolute;
        top: 0;
        left: 0;
        background-color: rgba(255, 255, 255, 0);
        #padding: 10px;
        #border: 1px solid #000;
        border-radius: 5px;
        display: none;
        width: 50px;
        height: 28px;
    }

    .hover-box {
        width: 80px;
        height: 80px;
        background-color: #aeaeae;
        margin: 20px auto;
        cursor: pointer;  // 箭头变为手指
    }
	
	.search-btn{
		background-color: #888;
		color: white;
		width: 50px;
		height: 28px;
		border:0;
		font-size: 12px;			
		border-radius: 30px;
	} 

</style>
<script>
    const hoverBoxList = document.querySelectorAll('.hover-box');
    const popUp = document.querySelector('.popUp');
    let isHovering = false; // 是否在弹框内部
	
	hoverBoxList.forEach(function(item,index,input){
		item.addEventListener('mouseout', () => {
			isHovering = false;
			const tuSearchActiveObj = document.querySelector('.tuSearchActive');
			if(!isEmptyObject(tuSearchActiveObj)){
				tuSearchActiveObj.classList.remove('tuSearchActive');
			}
			setTimeout(() => {
				if (!isHovering) {
					popUp.style.display = 'none';
				}
			}, 200); // 延迟 200ms 关闭弹框
		});
	});
	
	popUp.addEventListener('mouseover', () => {
        isHovering = true;
    });
    popUp.addEventListener('mouseout', () => {
        isHovering = false;
        setTimeout(() => {
            if (!isHovering) {
                popUp.style.display = 'none';
            }
        }, 200); // 延迟 200ms 关闭弹框
    });
	hoverBoxList.forEach(function(item,index,input){
		item.addEventListener('mousemove', (event) => {
			popUp.style.display = 'block';
			const boxRect = item.getBoundingClientRect();
			const popUpWidth = popUp.offsetWidth;
			const popUpHeight = popUp.offsetHeight;
			const popUpLeft = boxRect.left+ 5;
			const popUpTop = boxRect.top + 5; // 计算 .popUp 的 top 值
			popUp.style.left = popUpLeft + 'px';
			popUp.style.top = popUpTop + 'px';
			
			item.classList.add('tuSearchActive');
		});
	});
	
	function getElementObj(){
		const tuSearchActiveObj = document.querySelector('.tuSearchActive');
		console.log(tuSearchActiveObj)
		if(!isEmptyObject(tuSearchActiveObj)){
			alert(tuSearchActiveObj.src);
		}
	}
	
	function isEmptyObject(obj){
	　　 for(value in obj){
	　　　　return false;
	　　}
	　　return true;
	}
</script>
</body>
</html>